package com.example.jobback.common.controller;

import com.example.jobback.common.service.CommonService;
import com.example.jobback.req.common.password.RecoverPasswordReq;
import com.example.jobback.resp.common.city.GetCityResp;
import com.example.jobback.resp.common.city.GetProvinceByCityResp;
import com.example.jobback.resp.common.company.GetCompanyIndustryResp;
import com.example.jobback.resp.common.position.GetPositionAllMessageResp;
import com.example.jobback.resp.common.position.category.GetPositionCategoryResp;
import com.example.jobback.resp.common.position.industry.GetPositionIndustryResp;
import com.example.jobback.resp.common.position.name.GetPositionNameByIndustryIdResp;
import com.example.jobback.resp.common.position.name.GetPositionNameResp;
import com.example.jobback.resp.common.province.GetProvinceResp;
import com.example.jobback.result.Result;
import com.example.jobback.util.SecureEncryptionUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CommonController
 * @Description: 通用控制器
 * @Author: lhb
 * @Date: 2025/5/11
 */
@RestController
@RequestMapping("/common")
@Tag(name = "通用控制器",description = "不需要登录的接口，有些接口前端不需要用到")
public class CommonController {

    private final CommonService commonService;

    public CommonController(CommonService commonService) {
        this.commonService = commonService;
    }


    @Operation(summary = "发送验证码",description = "发送验证码接口",hidden = true)
    @PostMapping("/sendPhoneCode")
    public Result<Object> sendPhoneCode(@Parameter(description = "电话号码", required = true) @RequestParam String phone) throws Exception {
        return commonService.sendPhoneCode(phone);
    }


    @Operation(summary = "加密手机号转换",description = "测试使用，后端数据库存的是加密")
    @PostMapping("/decryptPhone")
    public Result<Object> decryptPhone(@Parameter(description = "加密电话号码", required = true) @RequestParam String phoneAes) throws Exception {
        return commonService.decryptPhone(phoneAes);
    }

    @Operation(summary = "密码破解",description = "测试使用，后端数据库存的是加密")
    @PostMapping("/decryptPassword")
    public Result<Object> decryptPassword(@Parameter(description = "加密密码", required = true) @RequestParam String passwordAes){
        return commonService.decryptPassword(passwordAes);
    }


    @Operation(summary = "密码加密",description = "测试使用")
    @PostMapping("encryptPassword")
    public Result<Object> encryptPassword(@Parameter(description = "密码", required = true) @RequestParam String password){
        return commonService.encryptPassword(password);
    }


    @Operation(summary = "获取所有省份或者直辖市",description = "如果属性中显示未直辖市，不建议再查询城市接口，建议储存地点都是市级" +
            "例如，厦门市你要查找就需要福建->厦门，但如果上海市就直接上海")
    @GetMapping("/getAllProvinces")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetProvinceResp>> getAllProvinces(){
        return commonService.getAllProvinces();
    }

    @Operation(summary = "根据省份id返回城市列表",description = "无")
    @GetMapping("getCitiesByProvinceId")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetCityResp>> getCitiesByProvinceId(@Parameter(description = "省份id", required = true)
                                                               @RequestParam Long id){
        return commonService.getCitiesByProvinceId(id);
    }

    @Operation(summary = "根据城市名称返回省份id和城市id",description = "前端编辑回显数据使用")
    @GetMapping("/getProvinceByCity")
    @ApiResponse(description = "返回响应体")
    public Result<GetProvinceByCityResp> getProvinceByCity(@Parameter(description = "城市名称", required = true)
                                                                           @RequestParam String cityName){
        return commonService.getProvinceByCity(cityName);
    }


    @Operation(summary = "获取所有公司行业",description = "无")
    @GetMapping("/getAllCompanyIndustries")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetCompanyIndustryResp>> getAllCompanyIndustries(){
        return commonService.getAllCompanyIndustries();
    }


    @Operation(summary = "获取职位行业列表",description = "职位行业对应着职位表中的职位类型positionType")
    @GetMapping("/getAllPositionIndustries")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetPositionIndustryResp>> getAllPositionIndustries(){
        return commonService.getAllPositionIndustries();
    }

    @Operation(summary = "根据职位行业id返回职位类别列表",description = "无")
    @GetMapping("/getPositionCategoriesByIndustryId")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetPositionCategoryResp>> getPositionCategoriesByIndustryId(@Parameter(description = "职位行业id", required = true)
                                                                                       @RequestParam Long id){
        return commonService.getPositionCategoriesByIndustryId(id);
    }

    @Operation(summary = "根据职位类别id返回职位名称列表",description = "这个职位名称的用途主要有：用户期望岗位，新增员工时的role，岗位名称")
    @GetMapping("/getPositionNamesByCategoryId")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetPositionNameResp>> getPositionNamesByCategoryId(@Parameter(description = "职位类别id", required = true)
                                                                              @RequestParam Long id){
        return commonService.getPositionNamesByCategoryId(id);
    }

    @Operation(summary = "根据职位行业id返回职位名称列表",description = "这个接口是为方便求职端首页，也可以不用，" +
            "其他端要用也行，但建议还是希望通过多次调用去获取名称")
    @GetMapping("/getPositionNamesByIndustryId")
    @ApiResponse(description = "返回响应体")
    public Result<List<GetPositionNameByIndustryIdResp>> getPositionNamesByIndustryId(@Parameter(description = "职位行业id", required = true)
                                                                          @RequestParam Long id){
        return commonService.getPositionNamesByIndustryId(id);
    }

    @Operation(summary = "根据职位行业名称，职位名称返回行业，类别，名称",description = "前端编辑回显使用")
    @GetMapping("/getPositionAllMessageByIndustryAndName")
    @ApiResponse(description = "返回响应体")
    public Result<GetPositionAllMessageResp> getPositionAllMessageByIndustryAndName(@Parameter(description = "行业名称", required = true)
                                                                                      @RequestParam String industryName,
                                                                                    @Parameter(description = "职位名称", required = true)
                                                 @RequestParam String detailName){
        return commonService.getPositionAllMessageByIndustryAndName(industryName, detailName);
    }

    @Operation(summary = "找回密码",description = "目前来讲，就是通过用户名校验，用户名忘了那没法子了")
    @PostMapping("recoverPassword")
    public Result<Object> recoverPassword(@Validated
                                              @RequestBody
                                              RecoverPasswordReq recoverPasswordReq){
        return commonService.recoverPassword(recoverPasswordReq);
    }

    @Operation(summary = "测试插入求职者",description = "测试插入数据使用")
    @PostMapping("insertSeeker")
    public Result<Object> insertSeeker(@RequestBody List<String> phoneList){
        return commonService.insertSeeker(phoneList);
    }
}
